package com.group3.controller.teacherController;

import com.group3.controller.Validated.Select;
import com.group3.domain.LeaveDetail;
import com.group3.pojo.receive.LeaveReceive;
import com.group3.pojo.result.LeaveDetailResult;
import com.group3.service.TeacherLeaveService;
import com.group3.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName TeacherLeaveController - 请假管理
 * @Author jt-sinlio，PX
 * @Time 2021/6/4 17:45
 **/


@Api(tags = "教师接口")
@RestController
@RequestMapping("/teacher/leave")
public class TeacherLeaveController {
    @Resource
    private TeacherLeaveService teacherLeaveService;

    //查询请假记录列表
    @ApiOperation(value = "查询请假记录列表")
    @GetMapping(value = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "submitTime", value = "提交时间",
                    dataType = "Date"),
            @ApiImplicitParam(name = "departName", value = "院系",
                    dataType = "Date"),
            @ApiImplicitParam(name = "professionName", value = "专业",
                    dataType = "Date"),
            @ApiImplicitParam(name = "submitTime", value = "年级",
                    dataType = "Date"),
            @ApiImplicitParam(name = "classId", value = "班级",
                    dataType = "Date"),
            @ApiImplicitParam(name = "studentId", value = "学号",//（精确匹配）
                    dataType = "String"),
            @ApiImplicitParam(name = "studentName", value = "学员名称",//（模糊查询）
                    dataType = "String"),
            @ApiImplicitParam(name = "theme", value = "请假主题",
                    dataType = "Date"),
            @ApiImplicitParam(name = "reason", value = "请假原因",
                    dataType = "Date"),
            @ApiImplicitParam(name = "state", value = "审批状态",
                    dataType = "Date")
    })
//    todo:测试成功
    public Result<LeaveDetail> selectLeave(
            @Validated(Select.class) LeaveReceive leaveReceive) {
        return teacherLeaveService.selectLeave(leaveReceive);
    }



    // 查询单条请假记录详情
    @ApiOperation(value = "查询单条请假记录详情")
    @GetMapping(value = "/resource")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leaveId", value = "请假记录id",
                    dataType = "Integer",required = true)
    })
    public Result<LeaveDetailResult> selectRecord(Integer leaveId) {
        return teacherLeaveService.selectLeaveByLeaveId(leaveId);
    }

    // 处理多条请假申请
    @ApiOperation(value = "处理多条请假申请")
    @PutMapping(value = "/apply")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leaveIds", value = "请假记录id记录", dataType = "List<Integer>",required = true),
            @ApiImplicitParam(name = "state", value = "审批状态",    dataType = "Integer")
    })
    public Result processingLeaves(List<Integer> leaveIds,Integer state) {
        return teacherLeaveService.processingLeaves(leaveIds,state);
    }

    // 处理一条请假申请不通过
    @ApiOperation(value = "处理一条请假申请不通过")
    @PutMapping(value = "/applyOneNo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leaveId", value = "请假记录id记录",
                    dataType = "Integer",required = true),
            @ApiImplicitParam(name = "reasons_failure", value = "通过原因",
                    dataType = "String")
    })
    public Result processingLeaveNo(@RequestParam Integer leaveId,
                                    @RequestParam String reasons_failure) {
        return teacherLeaveService.processingLeaveNo(leaveId,reasons_failure);
    }



}
